/**
 * The main QML file.
 *
 * (c) Copyright 2011 Nokia Corporation. All rights reserved.
 */

import Qt 4.7

import "../script/common.js" as CommonScript
import "../lib/components"

Image {
    id: backgroundImage;
    width: 360;
    height: 640;
    z: 1;
    source: "qrc:/gfx/background_360x640.png";

    // Top bar
    Rectangle {
        id: topBar;
        width: parent.width;
        height: 70;
        z: 1;

        // Logo
        Image {
            id: logo;
            x: 10;
            source: "qrc:/gfx/logo_112x60.png";
        }

        // Exit/Back button
        Image {
            id: btnExitBack;
            x: parent.width - 40;
            anchors.verticalCenter: parent.verticalCenter;
            source: (backFunctionality != CommonScript.EXIT) ?
                        "qrc:/gfx/buttons/back.png" :
                        "qrc:/gfx/buttons/exit.png";

            // Stores information about what the button does when clicked.
            property int backFunctionality;
            signal buttonClicked;

            MouseArea {
                anchors.fill: parent;

                onClicked: {
                    // Hide the Busy indicator
                    busyIndicator.opacity = 0;

                    btnExitBack.buttonClicked();
                }
            }
        }

        Rectangle {
            anchors.bottom: parent.bottom;
            width: parent.width;
            height: 2;
            color: "#aed99c";
        }
    }

    BusyIndicator {
        id: busyIndicator;
        x: parent.width / 2 - width / 2;
        y: parent.height / 2 - height / 2;
        z: 9;
        opacity: 0;
    }

    // Tabs
    TabWidget {
        id: tabs;
        x: 0;
        y: topBar.height;
        width: parent.width;
        height: parent.height - topBar.height;

        BetaView {
            property string title: "Latest";
            opacity: 0;

            Component.onCompleted: {
                backFunctionality = CommonScript.BACK_TO_BETA_LIST;
                getLatest();
            }
        }

        BetaView {
            property string title: "Popular";
            opacity: 0;

            Component.onCompleted: {
                backFunctionality = CommonScript.BACK_TO_BETA_LIST;
                getMostPopular();
            }
        }

        SearchView {
            property string title: "Search";
            opacity: 0;

            Component.onCompleted: fetchTags();
        }
    }
}
